/*package com.axs.logcollector.axs;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.log4j.Logger;


import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.SFTPv3Client;
import ch.ethz.ssh2.SFTPv3FileHandle;


public class FTPLogsHandler {
	private static final Logger m_logger = Logger.getLogger(FTPLogsHandler.class);
	
	public static final int SSH_TIMEOUT = 30 * 1000;
	public static final int RETRY_COUNT = 3;
	public static final int DEFAULT_CONNECTION_TIMEOUT = SSH_TIMEOUT; // 30 seconds
	
	public static final String AMS_LOG_DIR = "AMS_LOG_DIR";
	public static final int BYTE_LIMIT = 30000;

	public FTPLogsHandler() {
	}
	
	public void getLogDirectory() {
		
	}

	public void coppyLogsToLocal(String serverAddress, String remoteSourceFile, String localDestFile, long offset) throws Exception {
		Connection connection = getConnectionToServer(serverAddress, RETRY_COUNT);
		SFTPv3Client sftpClient = null;
		FileOutputStream fileOS = null;
		BufferedOutputStream bufferedOS = null;
		SFTPv3FileHandle fileHandle = null;
		try {
			sftpClient = getSFTPv3Client(connection);
			// Only need to open file for reading
			fileHandle = sftpClient.openFileRO(remoteSourceFile);
			File localFile = new File(localDestFile);
			if (!localFile.getParentFile().exists()) {
				//m_logger.debug("Create local dir: " + localFile.getParent());
				localFile.getParentFile().mkdirs();
			}

			fileOS = new FileOutputStream(localFile, true); // Writing the changed content to local file
			bufferedOS = new BufferedOutputStream(fileOS);

			if(offset < 0) {
				offset = 0;
			}

			byte[] data = new byte[BYTE_LIMIT];
			while (true) {
				int length = sftpClient.read(fileHandle, offset, data, 0, BYTE_LIMIT);
				//m_logger.debug("Length retrieved " + length + " " + (counter++));
				if (length == -1) {
					break;
				}
				bufferedOS.write(data, 0, length);
				bufferedOS.flush();
				offset += length;
			}
		} catch (Exception e) {
			//m_logger.info("Error in reading file" + remoteSourceFile, e);
			throw e;
		} finally {
			if (fileOS != null) {
				try {
					fileOS.close();
				} catch (IOException ignore) {
				}
			}
			if (bufferedOS != null) {
				try {
					bufferedOS.close();
				} catch (IOException ignore) {
				}
			}
			if (sftpClient != null && fileHandle != null) {
				try {
					sftpClient.closeFile(fileHandle);
				} catch (IOException ignore) {
				}
				close(sftpClient);
			}
			closeConnection(connection);
		}
	}

	public Connection getConnectionToServer(String serverIp, String userName, String password, int orgCounter)  {
		Connection connection = null;
		int counter = orgCounter;
		while (counter != 0) {
			try {
				connection =  new Connection(serverIp);
				m_logger.info("trying to connect remote server" + serverIp);
				connection.connect(null, DEFAULT_CONNECTION_TIMEOUT, 0);
				boolean isAuth = connection.authenticateWithPassword(userName, password);
				if (!isAuth) {
					System.out.println("Authenticate falied");
					closeConnection(connection);
					connection = null;
				}
				break;
			} catch (Exception e) {
				closeConnection(connection);
				// If an exception occurs, make the connection as null
				connection = null;
				if (isDeveloperMode()) {
					break;
				}
				//m_logger.error("Error while trying to connect server: ", e);
				// retry thrice
				//m_logger.info("Retry Connection");
				counter--;
			}
		}
		if (connection == null) {
			//throw new Exception("Can not open connection to server " + server);
		}
		return connection;
	}
	
	public Connection getConnectionToServer(String server, int orgCounter) {
		return getConnectionToServer(server, ExecutorHandler.DEFAULT_AMS_USER, ExecutorHandler.DEFAULT_AMS_PASSWORD, orgCounter);
	}

	private void close(SFTPv3Client client) {
		try {
			if (client != null) {
				client.close();
			}
		} catch (Exception ignore) { }
	}

	private void closeConnection(Connection conn) {
		try {
			if (conn != null) {
				conn.close();
			}
		} catch (Exception ignore) {
		}
	}

	private boolean isDeveloperMode() {
		String property = System.getProperty("developer");
		return property != null && Boolean.TRUE.equals(Boolean.valueOf(property));
	}

	protected SFTPv3Client getSFTPv3Client(Connection connection) throws IOException {
		return new SFTPv3Client(connection);
	}

	protected Connection getConnection(String serverIp) {
		return new Connection(serverIp);
	}

	public static void main(String[] args) throws Exception {
		//"ax5bUILd1123@TMA";
		//"10.0.0.6"
		//axsbuild
		FTPLogsHandler handler = new FTPLogsHandler();
		handler.getConnectionToServer("10.0.0.6", "axsbuild", "ax5bUILd1123@TMA", 3);
	}
}
*/